/********************************************************************************
  * @file     SD93F115B_pwr.h   						    	
  * @author   TEST TEAM 												    	
  * @version  v0															    	
  * @date     Septemper 2022												    	
  * @brief
  *
  * Copyright (C) 2022  Hangzhou SDIC Microelectronics Co., Ltd
**********************************************************************************/

#ifndef __SD93F115B_PWR_H
#define __SD93F115B_PWR_H

#ifdef __cplusplus
 extern "C" {
#endif

/*********************Includes*******************/
#include "SD93F115B.h"

/***************************************************/
								
/***************** ACM 输出电平设置*********************/
#define PWR_ACMLevel_VBG					((uint32_t)0x00000000)	
#define PWR_ACMLevel_VNTAT           		AP_CR_ACMPS_0
#define PWR_ACMLevel_AVDDR					AP_CR_ACMPS_1	
#define PWR_ACMLevel_DAO					AP_CR_ACMPS	

#define IS_PWR_ACM_LEVEL(LEVEL) (((LEVEL)==PWR_ACMLevel_VBG )||\
								 ((LEVEL)==PWR_ACMLevel_VNTAT)||\
								 ((LEVEL)==PWR_ACMLevel_AVDDR)||\
								 ((LEVEL)==PWR_ACMLevel_DAO))

/***************** AVDDR 输出电平设置*********************/
#define PWR_AVDDRLevel_2V4					((uint32_t)0x00000000)
#define PWR_AVDDRLevel_2V7           		AP_CR_AVDDRX_0
#define PWR_AVDDRLevel_3V0					AP_CR_AVDDRX_1	
#define PWR_AVDDRLevel_3V3					((uint32_t)0x00000006)
#define PWR_AVDDRLevel_3V6					AP_CR_AVDDRX_2	
#define PWR_AVDDRLevel_3V9           		((uint32_t)0x0000000A)
#define PWR_AVDDRLevel_4V2					((uint32_t)0x0000000C)	
#define PWR_AVDDRLevel_4V5					AP_CR_AVDDRX	

#define IS_PWR_AVDDR_LEVEL(LEVEL) (((LEVEL)==PWR_AVDDRLevel_2V4)||\
								   ((LEVEL)==PWR_AVDDRLevel_2V7)||\
								   ((LEVEL)==PWR_AVDDRLevel_3V0)||\
								   ((LEVEL)==PWR_AVDDRLevel_3V3)||\
								   ((LEVEL)==PWR_AVDDRLevel_3V6)||\
								   ((LEVEL)==PWR_AVDDRLevel_3V9)||\
								   ((LEVEL)==PWR_AVDDRLevel_4V2)||\
								   ((LEVEL)==PWR_AVDDRLevel_4V5))
								   
/***************** DVDDR LDO settle time设置*********************/
#define PWR_DVDDR_STLTM_64ms	    ((uint32_t)0x00)
#define PWR_DVDDR_STLTM_32ms	    ((uint32_t)0x01)
#define PWR_DVDDR_STLTM_16ms	    ((uint32_t)0x02)
#define PWR_DVDDR_STLTM_8ms	        ((uint32_t)0x03)	     
		

#define IS_PWR_DVDDR_STLTM(STLTM) (((STLTM)==PWR_DVDDR_STLTM_64ms)||\
								   ((STLTM)==PWR_DVDDR_STLTM_32ms)||\
								   ((STLTM)==PWR_DVDDR_STLTM_16ms)||\
								   ((STLTM)==PWR_DVDDR_STLTM_8ms)）

/***************** DVDDR 输出电平设置*********************/
#define PWR_DVDDRLevel_1V419				((uint8_t)0x00)	     
#define PWR_DVDDRLevel_1V465           		DLDO_CR_DVDDRX_0
#define PWR_DVDDRLevel_1V489				DLDO_CR_DVDDRX_1	
#define PWR_DVDDRLevel_1V502				((uint8_t)0x03)	
#define PWR_DVDDRLevel_1V514				DLDO_CR_DVDDRX_1	
#define PWR_DVDDRLevel_1V527           		((uint8_t)0x05)
#define PWR_DVDDRLevel_1V554				((uint8_t)0x06)
#define PWR_DVDDRLevel_1V609				DLDO_CR_DVDDRX_1		

#define IS_PWR_DVDDR_LEVEL(LEVEL) (((LEVEL)==PWR_DVDDRLevel_1V419 )||\
								   ((LEVEL)==PWR_DVDDRLevel_1V465)||\
								   ((LEVEL)==PWR_DVDDRLevel_1V489)||\
								   ((LEVEL)==PWR_DVDDRLevel_1V502)||\
								   ((LEVEL)==PWR_DVDDRLevel_1V514)||\
								   ((LEVEL)==PWR_DVDDRLevel_1V527)||\
								   ((LEVEL)==PWR_DVDDRLevel_1V554)||\
								   ((LEVEL)==PWR_DVDDRLevel_1V609))
/***************** DVDDR VREF设置*********************/
#define PWR_DVDDR_VREF_LPBG           		((uint32_t)0x00000000)
#define PWR_DVDDR_VREF_BGCHOP            	((uint32_t)0x00000001)
#define IS_PWR_DVDDR_VREFSEL(VREF) (((VREF)==PWR_DVDDR_VREF_LPBG)||((VREFL)==PWR_DVDDR_VREF_BGCHOP))
								  
/***************************DAC相关参数配置****************************/									  
typedef struct
{     	
	uint8_t DACP;                           //配置DAC正端信号        
    uint8_t DACN;                           //配置DAC负端信号	
	FunctionalState DAC_DAEN;               //使能AVDDR做DAC输入分压信号源
    uint16_t DACCode;                        //设置DAC码值
   
}DAC_InitTypeDef;


#define IS_PWR_DAC_InputPositiveChannel(Channel) (((Channel) >= 0)&&((Channel) <= 0x0A)||((Channel) == 0x0F)) 									  
#define IS_PWR_DAC_InputNegtiveChannel(Channel)  (((Channel) >= 0)&&((Channel) <= 0x05))
#define IS_PWR_DAC_Code(Code) (((Code) >= 0)&&((Code) <= 0xFFF))
	
/***************************LBT相关参数配置****************************/									  
typedef struct
{     	
	DAC_InitTypeDef PWR_DACInitStruct;          //配置DAC相关参数
    FunctionalState LBTINSELP30;                //使能P30为LBT引脚
	uint32_t PWR_COMPP;                         //配置LBT比较器正端输入信号
    FunctionalState LBT_COMPDelay2uSEN;         //使能LBT比较器输出2uS延时滤波
	
}LBT_InitTypeDef;

/***************** 比较器（COMP）正端输入信号选择*********************/
#define PWR_COMPP_VBG				((uint32_t)0x00000000)	     
#define PWR_COMPP_VSS           	LBT_CR_COMPX_0
#define PWR_COMPP_A10				LBT_CR_COMPX_1	
#define PWR_COMPP_A12				((uint32_t)0x00000003)	
#define PWR_COMPP_P01				LBT_CR_COMPX_2	
#define PWR_COMPP_P30           	((uint32_t)0x00000005)		

#define IS_PWR_COMP_Channel(Channel) (((Channel)==PWR_COMPP_VBG)||\
								      ((Channel)==PWR_COMPP_VSS)||\
								      ((Channel)==PWR_COMPP_A10)||\
								      ((Channel)==PWR_COMPP_A12)||\
								      ((Channel)==PWR_COMPP_P01)||\
								      ((Channel)==PWR_COMPP_P30))
									  
									  

/********************** TouchKey检测端口配置 *************************/
#define PWR_CAPMS_P00				  ((uint8_t)0x00)	     
#define PWR_CAPMS_P01           	  CAPM_CR_CAPMS_0
#define PWR_CAPMS_A12				  CAPM_CR_CAPMS_1	
#define PWR_CAPMS_A11				  ((uint8_t)0x06)	
#define PWR_CAPMS_A9				  CAPM_CR_CAPMS_2	
#define PWR_CAPMS_A8           	      ((uint8_t)0x0A)		

#define IS_PWR_TouchKey_Channel(Channel) (((Channel)==PWR_CAPMS_P00)||((Channel)==PWR_CAPMS_P01)||\
								          ((Channel)==PWR_CAPMS_A12)||((Channel)==PWR_CAPMS_A11)||\
								          ((Channel)==PWR_CAPMS_A9) ||((Channel)==PWR_CAPMS_A8))
									  

/***************** BG management functions ***********/	
void PWR_BGCmd(FunctionalState NewState);		                     //使能BG电路

/***************** ACM management functions ******************/	
void PWR_ACMLevelConfig(uint32_t PWR_ACMLevel);                      //配置ACM引脚输出电压
void PWR_ACMCmd(FunctionalState NewState);	                         //使能ACM电路

/***************** AVDDR management functions ******************/
void PWR_AVDDR_IBLEEDCmd(FunctionalState NewState);                  //AVDDR_IBLEED使能,开启增增加一个小电流负载以增强稳定性，可关闭节省电流
void PWR_AVDDRLevelConfig(uint32_t PWR_AVDDRLevel);                  //配置AVDDR的输出值
void PWR_AVDDRCmd(FunctionalState NewState);                         //使能AVDDR输出

/***************** DVDDR相关参数设置 **********************/
void PWR_DVDDRVREFSEL(uint32_t PWR_DVDDRVREFSEL);                    //DVDDR参考电压选择
void PWR_DVDDR_SOFTSTARTCmd(FunctionalState NewState);               //使能DVDDR电压软件修改
void PWR_DVDDR_EXTCAPSELCmd(FunctionalState NewState);               //使能DVDDR外挂电容（DVDDR外挂Cap时需要设为1，增强稳定性）
void PWR_DVDDR_IBLEEDENCmd(FunctionalState NewState);                //使能DVDDR小电流负载（开启增增加一个小电流负载以增强稳定性，可关闭节省40uA电流）
void PWR_DVDDRSTLTMConfig(uint32_t PWR_DVDDRSTLTM);	                 //DVDDR LDO settle time设置
void PWR_DVDDRLevelConfig(uint8_t PWR_DVDDRLevel);                   //配置DVDDR的输出电平，供芯片内部MCU、Flash等数字电路使用
void PWR_LVDCmd(FunctionalState NewState);                           //使能DVDDR低压检测功能，当发生低压时，芯片产生复位
void PWR_FlashLowpwrCmd(FunctionalState NewState);                   //使能正常模式时，不访问FLASH时，FLASH进行低功耗处理

/***************** DAC相关参数设置 **********************/
void PWR_DACInit(DAC_InitTypeDef*PWR_DACInitStruct);                 //初始化DAC的相关参数
void PWR_DACChannelConfig(uint8_t DACP,uint8_t DACN);                //配置DAC输入通道
void PWR_DAENCmd(FunctionalState NewState); 	                     //使能AVDDR做DAC输入分压信号源
void PWR_SetDACCode(uint16_t DACCode);                               //设置12位的DACCode
void PWR_AUDENCmd(FunctionalState NewState);                         //使能DAC AUD输出
void PWR_DAOENCmd(FunctionalState NewState);                         //使能DAC DAO输出

/***************** LBT相关参数设置 ****************************/
void PWR_LBTInit(LBT_InitTypeDef* PWR_LBTInitStruct);	             //初始化LBT相关参数
void PWR_LBTINSELP30Cmd(FunctionalState NewState);                   //使能P30为LBT引脚

void PWR_COMPDelay2uSCmd(FunctionalState NewState);                  //使能比较器输出2us延时滤波
void PWR_COMPChannelConfig(uint32_t PWR_COMPP);                      //配置比较器正端输入信号
void PWR_LBTCmd(FunctionalState NewState);                           //使能LBT功能

void PWR_LBTITCmd(FunctionalState NewState);	                     //使能LBT中断
ITStatus PWR_GetLBTITStatus(void);                                   //获取LBT中断标志位
void PWR_ClearLBTITStatus(void);                                     //清除LBT中断标志位

/***************** Touch Key 相关参数设置 **********************/
void PWR_TouchKeyChannelConfig(uint8_t PWR_CAPMS,FunctionalState NewState); //配置触摸按键检测入口，并使能触摸按键功能

#ifdef __cplusplus
}
#endif

#endif /* __SD93F115B_PWR_H */

/**********************************END OF FILE*********************************/

